const express = require('express');
const multer = require('multer');
const fs = require('fs');
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());

const storage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, 'uploads/');
  },
  filename: (req, file, cb) => {
    cb(null, file.originalname);
  }
}); 

const upload = multer({ storage: storage });

app.post('/upload', upload.single('file'), (req, res) => {
  const file = req.file;
  console.log(file);
  res.send('上传成功');
});

app.listen(3000, () => {
  console.log('启动服务:http://127.0.0.1:3000');
});